<template>
  <div class="fixed" v-dialogDrag>
    <div class="content el-dialog"
         style="padding:0">
      <div class="msgTop el-dialog__header">
        <span>催单</span>
        <i class="el-icon-close fr"
           style="cursor:pointer;line-height:40px;font-size:13px;"
           @click="cancelTransfer"></i>
      </div>
      <el-form :model="ruleForm"
               ref="ruleForm"
               class="demo-ruleForm"
               :rules="rules"
               style="padding:20px 20px 0 20px"
               label-width="100px">
        <el-form-item label="催单:"
                      label-width="60px"
                      prop="menuDesc">
          <el-input type="textarea"
                    v-model="ruleForm.menuDesc"
                    style="min-height:75px;"
                    :autosize="{ minRows: 3}">
          </el-input>
        </el-form-item>
        <el-form-item label-width="10px"
                      class="center">
          <el-button @click="submitForm('ruleForm')"
                     type="button"
                     class="el-button el-button--primary el-button--medium h30Btn ">确定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { insertBatch } from '@/api/WorkOrderUrgeController'
export default {
  data () {
    const character = (rule, value, callback) => {
      var reg = /^[\s　]*$/
      if (!value) {
        return callback(new Error('请填写'))
      } else if (reg.test(value)) {
        return callback(new Error('请填写正确的催单信息'));
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        menuDesc: ''
      },
      rules: {
        menuDesc: [
          { required: true, validator: character, trigger: ['blur'] }
        ]
      },
      workOrderIdList: ''
    }
  },
  mounted () {
  },
  methods: {
    cancelTransfer () {
      this.$emit('changeShow', { name: 'close', value: false })
      this.$refs.ruleForm.resetFields();
    },
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.workOrderIdList = JSON.parse(sessionStorage.getItem('workOrderIdList')) || this.$store.state.orderDetailsId
          let params = {
            content: this.ruleForm.menuDesc,
            userId: this.$store.state.userId,
            workOrderIdList: this.workOrderIdList
          }
          insertBatch(params).then(res => {
            if (res.data.retCode === 200) {
              this.$message({
                type: 'success',
                message: res.data.msg
              })
              this.$refs.ruleForm.resetFields();
              this.$emit('changeShow', { name: 'submit', value: false })
            } else {
              this.$message({
                type: 'error',
                message: res.data.msg
              })
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
.center {
  text-align: center;
  font-size: 16px;
}

.paging-foot {
  padding: 10px 0;
}

</style>
